import jdk.dynalink.linker.GuardedInvocationTransformer;

import javax.transaction.xa.Xid;
import java.util.*;
import java.util.stream.Collector;

public class Doudizhu {
    ArrayList<Card> cardlist = new ArrayList();

    public void inte() {
        for (int i = 1; i < 14; i++) {
            if (i == 1) {
                cardlist.add(new Card("A", "方片",12));
            } else if  (i==2){
                cardlist.add(new Card(i + "", "方片",13));
            }
            else if (i <= 10) {
                cardlist.add(new Card(i + "", "方片",i-2));
            } else if (i == 11) {
                cardlist.add(new Card("J", "方片",9));
            } else if (i == 12) {
                cardlist.add(new Card("Q", "方片",10));
            } else if (i == 13) {
                cardlist.add(new Card("K", "方片",11));
            }
        }
        for (int i = 1; i < 14; i++) {
            if (i == 1) {
                cardlist.add(new Card("A", "红桃",12));
            } else if  (i==2){
                cardlist.add(new Card(i + "", "红桃",13));
            }
            else if (i <= 10) {
                cardlist.add(new Card(i + "", "红桃",i-2));
            } else if (i == 11) {
                cardlist.add(new Card("J", "红桃",9));
            } else if (i == 12) {
                cardlist.add(new Card("Q", "红桃",10));
            } else if (i == 13) {
                cardlist.add(new Card("K", "红桃",11));
            }
        }
        for (int i = 1; i < 14; i++) {
            if (i == 1) {
                cardlist.add(new Card("A", "黑桃",12));
            } else if  (i==2){
                cardlist.add(new Card(i + "", "黑桃",13));
            }
            else if (i <= 10) {
                cardlist.add(new Card(i + "", "黑桃",i-2));
            } else if (i == 11) {
                cardlist.add(new Card("J", "黑桃",9));
            } else if (i == 12) {
                cardlist.add(new Card("Q", "黑桃",10));
            } else if (i == 13) {
                cardlist.add(new Card("K", "黑桃",11));
            }
        }
        for (int i = 1; i < 14; i++) {
            if (i == 1) {
                cardlist.add(new Card("A", "梅花",12));
            } else if  (i==2){
                cardlist.add(new Card(i + "", "梅花",13));
            }
            else if (i <= 10) {
                cardlist.add(new Card(i + "", "梅花",i-2));
            } else if (i == 11) {
                cardlist.add(new Card("J", "梅花",9));
            } else if (i == 12) {
                cardlist.add(new Card("Q", "梅花",10));
            } else {
                cardlist.add(new Card("K", "梅花",11));
            }
        }

        cardlist.add(new Card("小王",14));
        cardlist.add(new Card("大王",15));
    }

    public void xipai() {
        Collections.shuffle(cardlist);
    }

    public void fapai() {
        List<Card> play1 =  cardlist.subList(0,16);
        play1.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.daxiao- o1.daxiao;
            }
        });
        List<Card> play2 = cardlist.subList(17,33);
        play2.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.daxiao- o1.daxiao;
            }
        });
        List<Card> play3 = cardlist.subList(34,50);
        play3.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.daxiao- o1.daxiao;
            }
        });
        List<Card> dipai = cardlist.subList(51,54);
        dipai.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.daxiao- o1.daxiao;
            }
        });
        for (Card car:play1
             ) {
            System.out.println(car);
        }
        for (Card car:play2
        ) {
            System.out.println(car);
        }
        for (Card car:play3
        ) {
            System.out.println(car);
        }
        for (Card car:dipai
        ) {
            System.out.println(car);
        }

    }

    public static void main(String[] args) {
        Doudizhu doudizhu = new Doudizhu();
        doudizhu.inte();
        doudizhu.xipai();
        doudizhu.fapai();

    }
}
